package com.wzg.appframe.view;

import android.content.Context;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.wzg.appframe.R;
import com.wzg.appframe.action.BaseAction;
import com.wzg.appframe.action.InitAction;
import com.wzg.appframe.action.SettingAction;
import com.wzg.appframe.action.WebAction;
import com.wzg.appframe.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SettingActivity extends BaseActivity implements View.OnClickListener {


    @BindView(R.id.editText)
    EditText serverIPET;

    @BindView(R.id.editTextH5)
    EditText h5UrlET;

    @BindView(R.id.button)
    Button saveBtn;

    @BindView(R.id.version_tv)
    TextView version_TV;

    SettingAction action;


    @Override
    public void initViews() {
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        saveBtn.setOnClickListener(this);
    }

    @Override
    public void initData() {
        action = new SettingAction(this);
        action.toH5Page();

        String apiUrl = action.getSharedPreferenData(BaseAction.API_URL_KEY);
        serverIPET.setText(apiUrl);
        version_TV.setText("版本号:V" + action.getVerName() + "(" + action.getVersionCode() + ")");
        String h5PageUrl = action.getSharedPreferenData(BaseAction.APP_H5_URL);
        if (h5PageUrl == null || "".equals(h5PageUrl)){
            h5PageUrl = BaseAction.H5_URL;
        }
        h5UrlET.setText(h5PageUrl);

    }

    @Override
    public void onClick(View v) {
        if (v == saveBtn) {
            action.setSharedPreferenData("ERR_URL", "");
            String apiUrl = serverIPET.getText().toString();
            action.setSharedPreferenData(BaseAction.API_URL_KEY, apiUrl);
            String h5PageUrl = h5UrlET.getText().toString();
            action.setSharedPreferenData(BaseAction.APP_H5_URL, h5PageUrl);
            action.toH5Page();
            //调接口获取 H5前端访问地址，更新信息，存到本地。
//            action.getAppInfoFromServer();
        }
    }


}
